import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import MultipleLocator

# 使用字典存储各模型的数据,精排1
# data = {
#     'SVM': [0.7362, 0.7311, 0.7399, 0.7355],
#     'RNN': [0.8394, 0.8418, 0.8367, 0.8392],
#     'TextCNN': [0.8378, 0.8352, 0.8394, 0.8373],
#     'CA': [0.9452, 0.9361, 0.9511, 0.9471]
# }
# 使用字典存储各模型的数据,精排2
# data = {
#     'TextCNN ': [0.8394, 0.8418, 0.8367, 0.8392],
#     'Transformer': [0.8378, 0.8352, 0.8394, 0.8373],
#     'CT': [0.9452, 0.9361, 0.9511, 0.9471]
# }

# 使用字典存储各模型的数据,召回
# data = {
#     'SVM': [0.7362, 0.7311, 0.7399, 0.7355],
#     'RNN': [0.8707, 0.8529, 0.8719, 0.8629],
#     'SR': [0.9066, 0.9025, 0.9095, 0.9055]
# }

# 使用字典存储各模型的数据,精排2
# data = {
#     'TextCNN': [0.7362, 0.7311, 0.7399, 0.7355],
#     'Transformer': [0.8707, 0.8529, 0.8719, 0.8629],
#     'CT': [0.9066, 0.9025, 0.9095, 0.9055]
# }

# 使用字典存储各模型的数据,召回2
# data = {
#     'SVM ': [0.8394, 0.8418, 0.8367, 0.8392],
#     'CNN': [0.8378, 0.8352, 0.8394, 0.8373],
#     'CT': [0.9452, 0.9361, 0.9511, 0.9471]
# }

# 使用字典存储各模型的数据,精排3
# data = {
#     'TextCNN': [0.6002, 0.2679, 0.2987, 0.3824],
#     'Transformer': [0.6112, 0.2811, 0.3135, 0.4052],
#     'CT': [0.6405, 0.3125, 0.3247, 0.4261]
# }
data = {
    'CBR': [0.6002, 0.2679, 0.2987, 0.3824],
    'MFR': [0.6112, 0.2811, 0.3135, 0.4052],
    'SCT': [0.6405, 0.3125, 0.3247, 0.4261]
}


# 模型名称
models = list(data.keys())
# 设置柱状图宽度
bar_width = 0.15
# 设置横坐标位置
index = np.arange(len(['AUC', 'MRR', 'nDCG@5', 'nDCG@10']))

# 定义颜色和图案列表
# colors = ['r', 'g', 'b', 'y']
# hatches = ['//', '\\', '||', '++']

# 设置图表大小，这里将宽度设置为10英寸，高度设置为6英寸
plt.figure(figsize=(10, 6))

# 绘制柱子
for i, model in enumerate(models):
    plt.bar(index + i * bar_width, data[model], width=bar_width,
            label=model)

# 添加x轴标签
plt.xticks(index + 1.5 * bar_width, ['AUC', 'MRR', 'nDCG@5', 'nDCG@10'])
# 添加y轴标签
plt.ylabel('Score')
# 添加图表标题
plt.title('')
# 将图例位置修改为右上角
plt.legend(bbox_to_anchor=(0.9, 1.1), loc='upper left')

# 获取当前坐标轴对象
ax = plt.gca()
# 设置顶部和右侧边框颜色为透明
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')

# 设置y轴刻度间隔为0.02（可根据需要调整）
# y_major_locator = MultipleLocator(0.05)
# ax.yaxis.set_major_locator(y_major_locator)

# 设置y轴的范围，从0.5开始
# all_scores = [score for scores in data.values() for score in scores]
# max_score = max(all_scores)
# plt.ylim(0.5, max_score + 0.05)

# 显示图表
plt.show()